package main

func canCompleteCircuit(gas []int, cost []int) int {
	start := 0
	costGas := 0
	remainGas := 0
	for i := 0; i < len(gas); i++ {
		costGas += gas[i] - cost[i]
		remainGas += gas[i] - cost[i]
		if costGas < 0 {
			start = i + 1
			costGas = 0
		}
	}
	if remainGas < 0 {
		return -1
	}

	return start
}
